package com.four.marketing.controller;


import com.four.marketing.entity.Collage;
import com.four.marketing.service.CollageService;
import com.four.marketing.vo.CollageVo;
import com.guli.common.utils.R;
import com.guli.common.vo.ManageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 侯新伟
 * @since 2021-12-14
 */
@RestController
@RequestMapping("mark/collage")
public class CollageController {

    @Autowired
    private CollageService collageService;


    /**
     *
     * 拼团商品列表
     *
     * @param vo
     * @return
     */
    @PostMapping("/list")
    public R list(@RequestBody CollageVo vo){

        List<Collage> collageList = collageService.collageList(vo);

        return R.ok().put("list",collageList);
    }

    /**
     * 添加拼团商品
     * @param collage
     * @return
     */
    @PostMapping("/addCollage")
    public R addCollage(@RequestBody Collage collage){
        collageService.addCollage(collage);
        return R.ok();
    }

    /**
     * 查询所有商品信息
     * @return
     */
    @GetMapping("/getManage")
    public R findAllManage(){
        return collageService.findAllManage();
    }

    /**
     * 根据获取的商品id查询
     * @param id
     * @return
     */
    @GetMapping("/getManageById/{id}")
    public R getManageById(@PathVariable("id")Integer id){
        return  collageService.getManageById(id);
    }

    /**
     * 将数据上传es
     * @param id
     * @return
     */
    @PutMapping("upCollage/{id}")
    public R upCollage(@PathVariable("id")Integer id){
        collageService.upCollage(id);
        return R.ok();
    }

    /**
     * 从es中删除此数据
     * @param id
     * @return
     */
    @PutMapping("downCollage/{id}")
    public R downCollage(@PathVariable("id")Integer id){
        collageService.downCollage(id);
        return R.ok();
    }

    /**
     * 根据id查询拼团商品
     * 回显商品信息
     * @param id
     * @return
     */
    @GetMapping("selectById/{id}")
    public R selectCollageById(@PathVariable("id")Integer id){
        Collage collage=collageService.selectCollageById(id);
        return R.ok().put("collage",collage);
    }

    /**
     * 修改拼团商品
     * @param id
     * @param collage
     * @return
     */
    @PutMapping("updateCallage/{id}")
    public R updateCollage(@PathVariable("id")Integer id,@RequestBody Collage collage){
        collageService.updateCollage(id,collage);
        return R.ok();
    }

    /**
     * 添加拼团商品的时候，根据学则的商品id去查询图片
     * @param id
     * @return
     */
    @GetMapping("getPictureById/{id}")
    public R getPictureById(@PathVariable("id")Integer id){
        collageService.getPictureById(id);
        return R.ok();
    }
}
